Skip to content

Introduce IO::Event::WorkerPool for blocking_operation_wait.#139

Merged
samuel-williams-shopify merged 13 commits into
socketry:mainfrom
samuel-williams-shopify:native-work-pool
Jun 11, 2025
Merged

Introduce IO::Event::WorkerPool for blocking_operation_wait.#139
samuel-williams-shopify merged 13 commits into
socketry:mainfrom
samuel-williams-shopify:native-work-pool

Conversation

@samuel-williams-shopify
Copy link
Copy Markdown
Contributor

@samuel-williams-shopify samuel-williams-shopify commented Jun 8, 2025

This implements a thread-based worker pool that integrates with Ruby's experimental fiber scheduler blocking_operation_wait hook to handle blocking operations asynchronously. The WorkerPool uses feature detection to support the new rb_fiber_scheduler_blocking_operation_* functions introduced in recent Ruby versions, providing a promise-based interface for submitting work to a thread pool without blocking the event loop. For example, when blocking operations like large IO::Buffer.copy calls (>1MiB) release the GVL, fiber schedulers can delegate them to the worker pool, allowing the main thread to continue processing other fibers.

Types of Changes

  • New feature.

Contribution

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a thread‐based IO::Event::WorkerPool and integrates it into a test fiber scheduler via Ruby’s blocking_operation_wait hook, enabling non‐blocking execution of GVL‐releasing operations.

  • Introduces IO::Event::WorkerPool C extension and registers it in Init_IO_Event
  • Adds IO::Event::TestScheduler fixture to delegate blocking operations to the worker pool
  • Adds tests for pool construction, stats, and integration with large IO::Buffer.copy operations

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/io/event/worker_pool.rb New tests for pool instantiation, stats API, and scheduler integration
fixtures/io/event/test_scheduler.rb Defines IO::Event::TestScheduler to route blocking ops to WorkerPool
ext/io/event/worker_pool.h Declares the Init_IO_Event_WorkerPool initializer
ext/io/event/fiber.c Changed visibility of IO_Event_Fiber_current from static to global
ext/io/event/event.c Calls Init_IO_Event_WorkerPool to register the extension
ext/extconf.rb Adds worker_pool.c to the build list and feature detection for blocking hooks
Comments suppressed due to low confidence (4)

test/io/event/worker_pool.rb:11

  • [nitpick] Consider adding unit tests for WorkerPool#call to verify that submitted tasks execute and that the returned promise resolves or rejects correctly.
describe IO::Event::WorkerPool do

ext/extconf.rb:26

  • The build list includes "io/event/worker_pool.c" but that source file isn't committed. This will break compilation; ensure the .c implementation is present or remove it from $srcs.
$srcs = ["io/event/event.c", "io/event/time.c", "io/event/fiber.c", "io/event/worker_pool.c", "io/event/selector/selector.c"]

test/io/event/worker_pool.rb:7

  • The test requires io/event/test_scheduler, but the fixture file lives under fixtures/.... Consider using require_relative or adjusting $LOAD_PATH so the test can load the scheduler definition.
require "io/event/test_scheduler"

ext/io/event/fiber.c:38

  • [nitpick] IO_Event_Fiber_current was made a global symbol by removing static. Unless it needs external linkage, restore static to limit symbol exposure.
VALUE IO_Event_Fiber_current(void) {

@samuel-williams-shopify samuel-williams-shopify merged commit 0345ded into socketry:main Jun 11, 2025
36 of 40 checks passed
@samuel-williams-shopify samuel-williams-shopify deleted the native-work-pool branch June 11, 2025 10:39
@trevorturk
Copy link
Copy Markdown

This is very exciting to see! 👀

@ioquatix ioquatix added this to the v1.11.0 milestone Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants